﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;
using System.ComponentModel;

namespace Pong_Project.Views
{
    class InGame : View
    {
        private GameObjectManager gameObjectManager;
        private LevelManager levelManager;
        private SpriteFont scoreLeft, scoreRight;
        private Vector2 scoreLeftOrigin, scoreRightOrigin, scoreLeftPos, scoreRightPos;
        private Song bgm;
        private Texture2D background;
        // private static readonly InGame singletonInGame = new InGame();

        public InGame()
            : base()
        {
            gameObjectManager = new GameObjectManager();
            levelManager = new LevelManager();
            Score.GetInstance().AddSignee(this);
          
        }

    

        public override void LoadContent(ContentManager content)
        {
            gameObjectManager.LoadContent(content);
            scoreLeft = content.Load<SpriteFont>("ScoreLeft");
            scoreRight = content.Load<SpriteFont>("ScoreRight");
            bgm = content.Load<Song>("02_Ridge_Racer");
            background = content.Load<Texture2D>("Background");

            scoreLeftOrigin = scoreLeft.MeasureString("0") / 2;
            scoreLeftPos = new Vector2(Game.WindowWidth / 4, scoreLeftOrigin.Y);
            scoreRightOrigin = scoreRight.MeasureString("0") / 2;
            scoreRightPos = new Vector2(Game.WindowWidth * 3 / 4, scoreRightOrigin.Y);
        }

        public override void Update(GameTime gameTime)
        {
            if (Controls.PauseGame)
            {
                ViewManager.State = GameState.Pause;
            }

            if (Controls.MuteSound)
            {
                MediaPlayer.IsMuted = !MediaPlayer.IsMuted;
            }

            gameObjectManager.Update(gameTime);
            levelManager.Update(gameTime);
        }

        public void WatchScore(object sender, PropertyChangedEventArgs args)
        {
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            gameObjectManager.Draw(spriteBatch);
            spriteBatch.DrawString(scoreLeft, Score.GetInstance().ScoreLeft.ToString(), scoreLeftPos, Color.White, 0, scoreLeftOrigin, 1.0f, SpriteEffects.None, 1.0f);
            spriteBatch.DrawString(scoreRight, Score.GetInstance().ScoreRight.ToString(), scoreRightPos, Color.White, 0, scoreRightOrigin, 1.0f, SpriteEffects.None, 1.0f);
        }
    }
}
